/**
 * 2018年12月9日下午2:25:14
 * @author 谢进财
 */
package com.baihang.project.ds.controller;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.baihang.framework.controller.BaseController;
import com.baihang.project.ds.common.CommonService;
import com.baihang.project.ds.entity.LouDongEntity;
import com.baihang.project.ds.service.CollectionMonitorService;

/**
 * 收藏監控
 *
 */
@Controller
@RequestMapping("/collectionMonitor")
public class CollectionMonitorController extends BaseController {
	private static Logger logger = LoggerFactory.getLogger(CollectionMonitorController.class);
	@Autowired
	private CollectionMonitorService service;
	@Autowired
	private CommonService commonService;
	@RequestMapping
	public String index() {
		return "/project/ds/collectionMonitor/index";
	}
	
	@RequestMapping("/loudongData")
	public ModelAndView loudongData(){
		ModelAndView  mav = new ModelAndView("/project/ds/collectionMonitor/loudongData");
		List<LouDongEntity> list = commonService.getLouDong();
		System.err.println(list.size());
		mav.addObject("loudong",list);
		return mav;
	}
	@RequestMapping(value ="/getRoomMsg", produces="application/json;charset=UTF-8")
	@ResponseBody
	public String getRoomMsg(int id) {
		String json = commonService.getRoomMsg(id);
		return json;
	}
	/**
	 * 修改收藏
	 * @param type
	 * @param id
	 * @param count
	 * @return
	 */
	@RequestMapping(value ="/collectionUpdate", produces="application/json;charset=UTF-8")
	@ResponseBody
	public String collectionUpdate(String type,String id,String count) {
		logger.info("{},{},{}",type,id,count);
		//String json = service.collectionUpdate(type,id,count);
		String json = service.collectionUpdateForRedis(type,id,count);
		return json;
	}
	//清除真收藏
	@RequestMapping(value ="/ClearAllCollection", produces="application/json;charset=UTF-8")
	@ResponseBody
	public String ClearAllCollection() {
		//String json = service.ClearAllCollection();
		String json = service.ClearAllCollectionForRedis();
		return json;
	}
	/**
	 * 清除假收藏
	 * @return
	 */
	@RequestMapping(value ="/ClearJiaCollection", produces="application/json;charset=UTF-8")
	@ResponseBody
	public String ClearJiaCollection() {
		//String json = service.ClearJiaCollection();
		String json = service.ClearJiaCollectionForRedis();
		return json;
	}
	
	/**
	 * 双击获得对象的收藏数据
	 * @param type
	 * @param key
	 * @return
	 */
	@RequestMapping(value ="/dbClickGetValue", produces="application/json;charset=UTF-8")
	@ResponseBody
	public String dbClickGetValue(String type,String key) {
		logger.info("{},{},{}",type,key);
		//String json = service.dbClickGetValue(type,key);
		String json = service.dbClickGetValueForRedis(type,key);
		return json;
	}
	
	@RequestMapping("/downloadRoomCollection")
	public ResponseEntity<byte[]> downloadCustomerOne() throws Exception{	
		return service.downloadRoomCollection();
	}
}
